创建子弹类 | 您所在的位置:网站首页 › ak47 弹夹 › 创建子弹类 |
public class Bullet extends FaGame{ //定义尺寸,速度,方向 int width =10; int height =10; int spend = 7; Direction direction; //构造有参函数 public Bullet(String img,int x,int y,Game youxi,Direction direction){ super(img,x,y,youxi); this.Direction = direction; } //四个方法移动方法 public void upward{ y -= speed; } public void downward{ y += speed; } public void leftward{ x -= speed; } public void rightward{ x += speed; } //整合上面四个方法 public void go(){ switch(direction){ case LEFT: leftward() break; case UP : upward(); break; case DOWN : downward(); break; case RIGHT: rightward(); break; } } //重写paintself方法 @Override public void paintself(Graphics gggg){ gggg.drawImage(img,x,y,null); //调入go方法 this.go(); } //重写矩形方法 public Rectangle getRec(){ return new Rectangle(x,y,width,height); } } |
CopyRight 2018-2019 实验室设备网 版权所有 |